package com.sky.controller.user;

import com.sky.entity.Category;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: Sabrina
 * @Date:2025/06/10/18:44
 * @Description:
 */
@Slf4j
@RestController("userSetmealContoller")
@RequestMapping("/user/setmeal")
@Api(tags = "C端套餐浏览接口")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    //查询用cacheable
    @Cacheable(cacheNames = "userSetmealCache",key = "#categoryId")
    @GetMapping("/list")
    @ApiOperation("根据分类id查询套餐")
    public Result getSetmeal(Long categoryId){
        List<Setmeal> list = setmealService.getSetmeal(categoryId);
        return Result.success(list);
    }

    @Cacheable(cacheNames = "userSetmealCache",key = "#id")
    @GetMapping("/{id}")
    @ApiOperation("根据套餐id查询包含的菜品")
    public Result getDishesBySetmealId(Long id){
        List<DishItemVO> list = setmealService.getDishesBySetmealId(id);
        return Result.success(list);
    }
}
